<template>
  <div class="comment-replay">
    <van-nav-bar
    :title="comment.reply_count > 0 ? `${comment.reply_count}条回复` : '暂无回复'"
  >
  <van-icon
  slot="left"
  name="cross"
  @click="$emit('close')"
  />
  </van-nav-bar>
  <div class="scroll-wrap">
    <!-- 评论项 -->
  <CommentItem
  :comment="comment"
  @click-reply="isReplyshow = true"
  />
  <!-- 评论回复列表 -->
  <van-cell title="全部回复" />
  <commentlist
  :list="commentlist"
   :source="comment.com_id"
   type="c"
  />
  </div>
  <!-- 发布评论 -->
  <div class="post-wrap">
    <van-button size="small" round class="post-btn" @click="isReplyshow = true" >写评论</van-button>
    <van-popup
    v-model="isReplyshow"
    position="bottom"
    >
    <commentpost
      :target="comment.com_id"
      @post-success="onPostsuccess"
    />
  </van-popup>
  </div>
  </div>
</template>

<script>
import CommentItem from './comment-item.vue'
import commentlist from './article-comment.vue'
import commentpost from './article-list.vue'
export default {
  name: 'CommentReplay',
  components: {
    CommentItem,
    commentlist,
    commentpost
  },
  props: {
    comment: {
      type: Object,
      required: true
    },
    data () {
      return {
        isReplyshow: false,
        commentlist: [] // 评论列表
      }
    }
  },
  methods: {
    onPostsuccess (data) {
      // 更新数量
      this.comment.reply_count++
      // 关闭弹层
      this.isReplyshow = false
      // 最新数据展示到列表顶部
      console.log(this.commentlist)
      this.commentlist.unshift(data.new_obj)
    }
  }
}
</script>

<style scoped lang="less">
.scroll-wrap{
  position: absolute;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}
.post-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-content: center;
  justify-content: center;
  background-color: #fff;
  .post-btn{
    width: 60%;
    border-top: 1px solid #d8d8d8;
  }
}
</style>
